/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmConsultaUsuario.java
 *
 * Created on 26/10/2009, 23:15:06
 */

package nivelacesso.telas;

import conexao.DAOException;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import nivelacesso.bd.NivelDao;
import nivelacesso.classes.Nivel;
import nivelacesso.classes.NivelTableModel;

/**
 *
 * @author Wolverine
 */
public class FrmConsultaNivel extends javax.swing.JFrame {

    private NivelDao dao = null;
    private NivelTableModel model = null;
    private Nivel nivel;

    /** Creates new form FrmConsultaUsuario */
    public FrmConsultaNivel() throws DAOException {
        try {
            dao = new NivelDao();
            List<Nivel> listaNivel = dao.consultarNivel();
            model = new NivelTableModel(listaNivel);
        } catch (DAOException ex) {
            ex.printStackTrace();
            model = new NivelTableModel(new ArrayList<Nivel>());
        }
        initComponents();
        URL url = this.getClass().getResource("/imagens/logo_mini.png");
        Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(url);
        this.setIconImage(imagemTitulo);
        this.setLocationRelativeTo(null);
        try{
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
        }catch (Exception e){
        }
        niveljTable.setModel(model);
        niveljTable.getColumnModel().getColumn(0).setPreferredWidth(50);
        niveljTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        niveljTable = new javax.swing.JTable();
        nivelAdcionarjButton = new javax.swing.JButton();
        nivelAlterarjButton = new javax.swing.JButton();
        nivelExcluirjButton = new javax.swing.JButton();
        nivelVoltarjButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        niveljTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null}
            },
            new String [] {
                "Title 1", "Title 2"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(niveljTable);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 420, 170));

        nivelAdcionarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/acessomais.png"))); // NOI18N
        nivelAdcionarjButton.setText("Adicionar");
        nivelAdcionarjButton.setToolTipText("Adicionar Professor");
        nivelAdcionarjButton.setFocusable(false);
        nivelAdcionarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nivelAdcionarjButton.setMaximumSize(new java.awt.Dimension(90, 80));
        nivelAdcionarjButton.setMinimumSize(new java.awt.Dimension(90, 80));
        nivelAdcionarjButton.setPreferredSize(new java.awt.Dimension(90, 80));
        nivelAdcionarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nivelAdcionarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nivelAdcionarjButtonActionPerformed(evt);
            }
        });
        getContentPane().add(nivelAdcionarjButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, -1, -1));

        nivelAlterarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/acessoedit.png"))); // NOI18N
        nivelAlterarjButton.setText("Alterar");
        nivelAlterarjButton.setToolTipText("Alterar Professor");
        nivelAlterarjButton.setFocusable(false);
        nivelAlterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nivelAlterarjButton.setMaximumSize(new java.awt.Dimension(90, 80));
        nivelAlterarjButton.setMinimumSize(new java.awt.Dimension(90, 80));
        nivelAlterarjButton.setPreferredSize(new java.awt.Dimension(90, 80));
        nivelAlterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nivelAlterarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nivelAlterarjButtonActionPerformed(evt);
            }
        });
        getContentPane().add(nivelAlterarjButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 180, -1, -1));

        nivelExcluirjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/acessomenos.png"))); // NOI18N
        nivelExcluirjButton.setText("Excluir");
        nivelExcluirjButton.setToolTipText("Excluir Professor");
        nivelExcluirjButton.setFocusable(false);
        nivelExcluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nivelExcluirjButton.setMaximumSize(new java.awt.Dimension(90, 80));
        nivelExcluirjButton.setMinimumSize(new java.awt.Dimension(90, 80));
        nivelExcluirjButton.setPreferredSize(new java.awt.Dimension(90, 80));
        nivelExcluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nivelExcluirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nivelExcluirjButtonActionPerformed(evt);
            }
        });
        getContentPane().add(nivelExcluirjButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 180, -1, -1));

        nivelVoltarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/voltar.png"))); // NOI18N
        nivelVoltarjButton.setText("Voltar");
        nivelVoltarjButton.setToolTipText("Voltar");
        nivelVoltarjButton.setFocusable(false);
        nivelVoltarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nivelVoltarjButton.setMaximumSize(new java.awt.Dimension(90, 80));
        nivelVoltarjButton.setMinimumSize(new java.awt.Dimension(90, 80));
        nivelVoltarjButton.setPreferredSize(new java.awt.Dimension(90, 80));
        nivelVoltarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        getContentPane().add(nivelVoltarjButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 180, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nivelAdcionarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nivelAdcionarjButtonActionPerformed
        new FrmCadastroNivel(null);
    }//GEN-LAST:event_nivelAdcionarjButtonActionPerformed

    private void nivelAlterarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nivelAlterarjButtonActionPerformed
        try{
            System.out.println(niveljTable.getSelectedRow());
            if (niveljTable.getSelectedRow()>=0){
                nivel = model.getNivel(niveljTable.getSelectedRow());
                new FrmCadastroNivel(nivel);
            }
        }catch (Exception ex){
            JOptionPane.showMessageDialog(null, "Erro na Alteração\n" + ex);
        }
    }//GEN-LAST:event_nivelAlterarjButtonActionPerformed

    private void nivelExcluirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nivelExcluirjButtonActionPerformed
               try{
            if (niveljTable.getSelectedRow()>=0){
                nivel = model.getNivel(niveljTable.getSelectedRow());
                dao.excluirNivel(nivel);
            }
        }catch (Exception ex){
            JOptionPane.showMessageDialog(null, "Erro ao Excluir\n" + ex);
        }
    }//GEN-LAST:event_nivelExcluirjButtonActionPerformed

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton nivelAdcionarjButton;
    private javax.swing.JButton nivelAlterarjButton;
    private javax.swing.JButton nivelExcluirjButton;
    private javax.swing.JButton nivelVoltarjButton;
    private javax.swing.JTable niveljTable;
    // End of variables declaration//GEN-END:variables

}
